home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / MDEF__ / UTILITIE.C < prev    next >
C/C++ Source or Header  |  1988-01-02  |  2KB  |  139 lines

  1. #include "MacTypes.h"
  2. #include "Quickdraw.h"
  3. #include "WindowMgr.h"
  4.  
  5. #define        ONE         65536L
  6. #define        ZOOMSTEPS    16
  7.  
  8. Fixed    fract;
  9.  
  10. int blend(i1,i2)
  11. int    i1,i2;
  12.     {
  13.     Fixed    smallFix,bigFix,tempFix;
  14.  
  15.     smallFix = ONE * i1;
  16.     bigFix = ONE * i2;
  17.     tempFix = FixMul(fract,bigFix)+FixMul(ONE-fract,smallFix);
  18.     return(FixRound(tempFix));
  19.     }
  20.  
  21. zoomrect(smallrect,bigrect,zoomup)
  22. Rect    *smallrect,*bigrect;
  23. Boolean    zoomup;
  24. {
  25.     Fixed        factor;
  26.     Rect        rect1,rect2,rect3,rect4;
  27.     GrafPtr        savePort,deskPort;
  28.     int            i;
  29.     
  30.     GetPort(&savePort);
  31.     OpenPort(deskPort = (GrafPtr)NewPtr(sizeof(GrafPort)));
  32.     InitPort(deskPort);
  33.     SetPort(deskPort);
  34.     PenPat(gray);
  35.     PenMode(notPatXor);
  36.     if (zoomup){
  37.         rect1 = *smallrect;
  38.         factor = FixRatio(6,5);
  39.         fract = FixRatio(541,10000);
  40.     }
  41.     else{
  42.         rect1 = *bigrect;
  43.         factor = FixRatio(5,6);
  44.         fract = ONE;
  45.     }
  46.     rect2 = rect1;
  47.     rect3 = rect1;
  48.     FrameRect(&rect1);
  49.     for (i=1;i<=ZOOMSTEPS;i++){
  50.         rect4.left = blend(smallrect->left,bigrect->left);
  51.         rect4.right = blend(smallrect->right,bigrect->right);
  52.         rect4.top = blend(smallrect->top,bigrect->top);
  53.         rect4.bottom = blend(smallrect->bottom,bigrect->bottom);
  54.         FrameRect(&rect4);
  55.         FrameRect(&rect1);
  56.         rect1 = rect2;
  57.         rect2 = rect3;
  58.         rect3 = rect4;
  59.         fract = FixMul(fract,factor);
  60.     }
  61.     FrameRect(&rect1);
  62.     FrameRect(&rect2);
  63.     FrameRect(&rect3);
  64.     ClosePort(deskPort);
  65.     DisposPtr((Ptr)deskPort);
  66.     PenNormal();
  67.     SetPort(savePort);
  68. }
  69.  
  70. ltog(r)
  71. Rect    *r;
  72. {
  73.     Point    p1,p2;
  74.  
  75.     p1 = topLeft(*r);
  76.     p2 = botRight(*r);
  77.     LocalToGlobal(&p1);
  78.     LocalToGlobal(&p2);
  79.     Pt2Rect(p1,p2,r);
  80. }
  81.  
  82. zoomport(wind,up)
  83. WindowPtr    wind;
  84. Boolean        up;
  85. {
  86.     Rect    r1,r2,r3;
  87.     
  88.     SetPort(wind);
  89.     SetRect(&r1,0,20,0,20);
  90.     r3 = wind->portRect;
  91.     r2 = r3;
  92.     InsetRect(&r2,(r3.right-r3.left+20)/2,(r3.bottom-r3.top+20)/2);
  93.     
  94.     ltog(&r2);
  95.     ltog(&r3);
  96.     
  97.     if (up){
  98.         zoomrect(&r1,&r2,TRUE);
  99.         zoomrect(&r2,&r3,TRUE);
  100.         ShowWindow(wind);
  101.         SetPort(wind);
  102.     }
  103.     else{
  104.         HideWindow(wind);
  105.         zoomrect(&r2,&r3,FALSE);
  106.         zoomrect(&r1,&r2,FALSE);
  107.     }
  108. }
  109.     
  110. centerwindow(wind,r)
  111. WindowPtr    wind;
  112. Rect        *r;
  113. {
  114.     Rect    r2;
  115.     int        windW,windH;
  116.     int        rectW,rectH;
  117.     
  118.     r2 = wind->portRect;
  119.         
  120.     windW = r2.right-r2.left;
  121.     windH = r2.bottom-r2.top;
  122.     
  123.     rectW = r->right-r->left;
  124.     rectH = r->bottom-r->top;
  125.     
  126.     MoveWindow    (wind,
  127.                 r->left+(rectW-windW)/2,
  128.                 r->top+(rectH-windH)/2,
  129.                 FALSE);
  130. }
  131.  
  132. centerrect(r1,r2)
  133. Rect    *r1,*r2;
  134. {
  135.     OffsetRect    (r1,
  136.                 ((r2->right-r2->left)-(r1->right-r1->left))/2-r1->left,
  137.                 ((r2->bottom-r2->top)-(r1->bottom-r1->top))/2-r1->top);
  138. }
  139.